import { createRouter, RouteRecordRaw, createWebHashHistory } from 'vue-router'
import Layout from '@/layout/index.vue'

// 扩展继承属性
interface extendRoute {
  hidden?: boolean
}
//
import errorRouter from './modules/error'
import orderRouter from './modules/order'
import netRouter from './modules/network'
import userRouter from './modules/users'
import codeRouter from './modules/codes'
import storageRouter from './modules/storage'
import busicRouter from './modules/busic'
// import appRouter from './modules/appcenter'
// import serviceRouter from './modules/service'
import noteRouter from './modules/note'
import baseRouter from './modules/base'
import knowRouter from './modules/know'
import merchantRouter from './modules/merchant'
import commodiRouter from './modules/commodity'
// import remoteVideoRouter from './modules/remoteVideo'
// import shopRouter from './modules/shop'
import withdrawalRouter from './modules/withdrawal'
// 异步组件
export const asyncRoutes = [
  ...orderRouter,
  ...netRouter,
  ...userRouter,
  ...merchantRouter,
  ...commodiRouter,
  ...codeRouter,
  ...storageRouter,
  ...withdrawalRouter,
  ...knowRouter,
  // ...remoteVideoRouter,
  // ...shopRouter,
  ...baseRouter,
  ...busicRouter,
  // ...appRouter,
  // ...serviceRouter,
  ...noteRouter,

  {
    path: '/:pathMatch(.*)',
    redirect: '/404',
  },
]

/**
 * path ==> 路由路径
 * name ==> 路由名称
 * component ==> 路由组件
 * redirect ==> 路由重定向
 * alwaysShow ==> 如果设置为true，将始终显示根菜单，无论其子路由长度如何
 * hidden ==> 如果“hidden:true”不会显示在侧边栏中（默认值为false）
 * keepAlive ==> 设为true 缓存
 * meta ==> 路由元信息
 * meta.title ==> 路由标题
 * meta.icon ==> 菜单icon
 * meta.affix ==> 如果设置为true将会出现在 标签栏中
 * meta.breadcrumb ==> 如果设置为false，该项将隐藏在breadcrumb中（默认值为true）
 */

export const constantRoutes: Array<RouteRecordRaw & extendRoute> = [
  ...errorRouter,
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index.vue'),
    hidden: true,
    meta: { title: '登录' },
    children: [
      {
        path: 'index',
        component: () => import('@/views/login/components/LoginForm.vue'),
        name: 'index',
        meta: { title: '登录-叮咚到家' },
      },
      {
        path: 'roles',
        component: () => import('@/views/login/components/slRoles.vue'),
        name: 'roles',
        meta: { title: '选择角色' },
      },
      {
        path: 'register',
        component: () => import('@/views/login/components/RegisterForm.vue'),
        name: 'register',
        meta: { title: '注册' },
      },
      {
        path: 'resuccess',
        component: () => import('@/views/login/components/ReSuccess.vue'),
        name: 'resuccess',
        meta: { title: '注册成功' },
      },
      {
        path: 'forget',
        component: () => import('@/views/login/components/forGet.vue'),
        name: 'forget',
        meta: { title: '忘记密码' },
      },
    ],
  },
  {
    path: '/',
    name: 'layout',
    component: Layout,
    redirect: '/home',
    // hidden: true,
    children: [
      {
        path: '/home',
        component: () => import('@/views/home/index.vue'),
        name: 'home',
        meta: { title: '数据看板', icon: 'House', affix: true, role: ['other'] },
      },
    ],
  },
]

const router = createRouter({
  // history: createWebHistory(process.env.BASE_URL), // history
  history: createWebHashHistory(), // hash
  routes: constantRoutes,
})
export default router
